package com.wkg.lotterysystem.dao.mapper;

import com.wkg.lotterysystem.dao.dataobject.ActivityDo;
import com.wkg.lotterysystem.dao.dataobject.ActivityPrizeDo;
import jakarta.validation.constraints.NotNull;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityPrizeMapper {


    @Insert({
            " <script>",
            " INSERT INTO activity_prize (activity_id, prize_id, prize_amount, prize_tiers, status) VALUES ",
            " <foreach collection='items' item='item' index='index' separator=','>",
            " (#{item.activityId}, #{item.prizeId}, #{item.prizeAmount}, #{item.prizeTiers}, #{item.status})",
            " </foreach>",
            " </script>"
    })
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    int batchInsert(@Param("items") List<ActivityPrizeDo> activityPrizeDoList);

    @Select("select * from activity_prize where activity_id = #{activityId}")
    List<ActivityPrizeDo> selectByActivityId(@Param("activityId") Integer activityId);

    @Select("select * from activity_prize where activity_id = #{activityId} and prize_id=#{prizeId}")
    ActivityPrizeDo selectByAPId(@Param("prizeId") Integer prizeId,
                                 @Param("activityId") Integer activityId);

    @Select("select count(1) from activity_prize where activity_id=#{activityId} and status=#{status}")
    int countPrize(@Param("activityId") Integer activityId, @Param("status") String status);

    @Update("update activity_prize set status=#{status} where activity_id=#{activityId} and prize_id=#{prizeId}")
    void updateStatus(@Param("activityId") Integer activityId,
                      @Param("prizeId") Integer prizeId,
                      @Param("status") String status);
}



